﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization;
using System.Diagnostics;
using System.Xml;
using CLRNet = System.Net;

namespace Microsoft.MSE.Catalog.Contracts
{
    #region Enumerations

    [DataContract(Namespace = SC.Namespace)]
    public enum EntityClass
    {
        [EnumMember]
        RuntimeServer = 0,
        [EnumMember]
        Endpoint = 2,
        [EnumMember]
        Operation = 4,
        [EnumMember]
        Binding = 6,
        [EnumMember]
        Channel = 7,
        [EnumMember]
        Policy = 8,
        [EnumMember]
        Schema = 9,
        [EnumMember]
        Property = 10,
        [EnumMember]
        OperationGroup = 11,
        [EnumMember]
        System = 12,
        [EnumMember]
        SystemInstance = 14,
        [EnumMember]
        Resource = 16,
        [EnumMember]
        BindingElements = 17,
        [EnumMember]
        AssertionType = 18,
        [EnumMember]
        PolicyAssertion = 19,
        [EnumMember]
        DataEntity = 20,
        [EnumMember]
        OperationVersion = 21,
        [EnumMember]
        SchemaObject = 22
    }

    [DataContract(Namespace = SC.Namespace)]
    public enum SchemaObjectType
    {
        [EnumMember]
        Unknown = 0,
        [EnumMember]
        SimpleType,
        [EnumMember]
        ComplexType,
        [EnumMember]
        Element,
        [EnumMember]
        Attribute,
        [EnumMember]
        AttributeGroup
    }

    [DataContract(Namespace = SC.Namespace)]
    public enum BindingElementType
    {
        [EnumMember]
        BaseBinding = 0,
        [EnumMember]
        Binding = 1,
        [EnumMember]
        BindingElement = 2
    }
    
    #endregion

    #region Base Entities

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public abstract class BaseEntity
    {
        protected Guid id;

        [DataMember(IsRequired = false)]
        public virtual Guid ID
        {
            get { return id; }
            set { id = value; }
        }
        protected string name;

        [DataMember(IsRequired = false)]
        public virtual string Name
        {
            get { return name; }
            set { name = value; }
        }
        protected string description;

        [DataMember(IsRequired = false)]
        public virtual string Description
        {
            get { return description; }
            set { description = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public abstract class BaseEntityListElement : BaseEntity
    {
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public abstract class BaseEntityGroupListElement : BaseEntityListElement
    {
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public abstract class BaseEntityGroupList<T> : BaseEntityList<T> where T : BaseEntityGroupListElement
    {
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public abstract class BaseEntityList<T> where T : BaseEntity 
    {
        protected List<T> _items;

        public List<T> Items
        {
            get
            {
                return _items;
            }
        }

        public virtual T this[Guid id]
        {
            get 
            {
                if (_items != null)
                    return _items.SingleOrDefault(x => x.ID == id);
                else
                    return null;
            }
            set
            {
                if (_items == null)
                {
                    _items = new List<T>();
                    if (value != null)
                    {
                        // It is an Add
                        value.ID = id;
                        _items.Add(value);
                    }
                }
                else 
                {
                    T item = _items.SingleOrDefault(x => x.ID == id);
                    if (item == null)
                    {
                        // It is an Add
                        if (value != null)
                            _items.Add(value);
                    }
                    else
                    {
                        if (value != null)
                        {
                            // It is an Update
                            _items.Remove(item);
                            value.ID = id;
                            _items.Add(value);
                        }
                        else
                        {
                            // It is a Delete
                            _items.Remove(item);
                        }
                    }
                }
            }
        }

        public virtual T this[string name]
        {
            get
            {
                if (_items != null)
                    return _items.SingleOrDefault(x => x.Name == name);
                else
                    return null;
            }
            set
            {
                if (_items != null)
                {
                    _items = new List<T>();
                }
                if (value != null)
                {
                    // ADD / UPDATE
                    T item = _items.SingleOrDefault(x => x.Name == name);
                    if (item == null)
                    {
                        _items.Add(value);
                    }
                    else
                    {
                        _items.Remove(item);
                        value.Name = name;
                        _items.Add(value);
                    }
                    _items.Add(value);
                }
                else
                {
                    // DELETE
                    T item = _items.SingleOrDefault(x => x.Name == name);
                    if (item != null)
                    {
                        _items.Remove(item);
                    }
                }
            }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public abstract class BaseEntityGroup<T> : BaseEntity where T : BaseEntityListElement 
    {
        protected List<T> _items;

        public virtual T this[Guid id]
        {
            get
            {
                if (_items != null)
                    return _items.Single(x => x.ID == id);
                else
                    return null;
            }
            set
            {
                if (_items != null)
                {
                    _items = new List<T>();
                    value.ID = id;
                    _items.Add(value);
                }
                else
                {
                    T item = _items.Single(x => x.ID == id);
                    if (item == null)
                    {
                        _items.Add(value);
                    }
                    else
                    {
                        _items.Remove(item);
                        value.ID = id;
                        _items.Add(value);
                    }
                }
            }
        }

        public virtual T this[string name]
        {
            get
            {
                if (_items != null)
                    return _items.Single(x => x.Name == name);
                else
                    return null;
            }
            set
            {
                if (_items != null)
                {
                    _items = new List<T>();
                    _items.Add(value);
                }
                else
                {
                    T item = _items.Single(x => x.Name == name);
                    if (item == null)
                    {
                        _items.Add(value);
                    }
                    else
                    {
                        _items.Remove(item);
                        value.Name = name;
                        _items.Add(value);
                    }
                }
            }
        }
    }

    #endregion Base Entities

    #region Entity

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class Entity : BaseEntity 
    {
        EntityClass entityClass;

        [DataMember(IsRequired = true)]
        public EntityClass EntityClass
        {
            get { return entityClass; }
            set { entityClass = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class EntityGroup : BaseEntity
    {
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class EntityGroupList : BaseEntityList<EntityGroupListElement>
    {
        [DataMember(IsRequired = false)]
        public List<EntityGroupListElement> EntityGroups
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class EntityGroupListElement : BaseEntityListElement
    {
    }


    #endregion Entity

    #region RuntimeServer

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class RuntimeServerList : BaseEntityList<RuntimeServerListElement>
    {
        [DataMember(IsRequired = false)]
        public List<RuntimeServerListElement> RuntimeServers
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class RuntimeServerListElement : BaseEntityListElement
    {
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class RuntimeServerNotificationList
    {
        List<RuntimeServerNotificationListElement> runtimeservers;

        [DataMember(IsRequired = false)]
        public List<RuntimeServerNotificationListElement> RuntimeServers
        {
            get { return runtimeservers; }
            set { runtimeservers = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class RuntimeServerNotificationListElement
    {
        [DataMember(IsRequired = true)]
        public Guid ID { get; set; }

        [DataMember(IsRequired = true)]
        public string Name { get; set; }

        [DataMember(IsRequired = false)]
        public string NotificationUrl { get; set; }

        [DataMember(IsRequired = false)]
        public Guid BindingID { get; set; }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class RuntimeServer : BaseEntity 
    {
        private string catalogURI;

        [DataMember(IsRequired = true)]
        public string CatalogURI
        {
            get { return catalogURI; }
            set { catalogURI = value; }
        }

        private MSEBinding catalogBinding;

        [DataMember(IsRequired = true)]
        public MSEBinding CatalogBinding
        {
            get { return catalogBinding; }
            set { catalogBinding = value; }
        }

        private string notificationURI;

        [DataMember(IsRequired = true)]
        public string NotificationURI
        {
            get { return notificationURI; }
            set { notificationURI = value; }
        }

        private MSEBinding notificationBinding;

        [DataMember(IsRequired = true)]
        public MSEBinding NotificationBinding
        {
            get { return notificationBinding; }
            set { notificationBinding = value; }
        }

        private string hostName;

        [DataMember(IsRequired = true)]
        public string HostName
        {
            get { return hostName; }
            set { hostName = value; }
        }

        private string brokerURI;

        [DataMember(IsRequired = true)]
        public string BrokerURI
        {
            get { return brokerURI; }
            set { brokerURI = value; }
        }

        private MSEBinding brokerBinding;

        [DataMember(IsRequired = true)]
        public MSEBinding BrokerBinding
        {
            get { return brokerBinding; }
            set { brokerBinding = value; }
        }

        private string listenerURI;

        [DataMember(IsRequired = true)]
        public string ListenerURI
        {
            get { return listenerURI; }
            set { listenerURI = value; }
        }

        private MSEBinding listenerBinding;

        [DataMember(IsRequired = true)]
        public MSEBinding ListenerBinding
        {
            get { return listenerBinding; }
            set { listenerBinding = value; }
        }

        private Policy policy;

        [DataMember(IsRequired = false)]
        public Policy Policy
        {
            get { return policy; }
            set { policy = value; }
        }

        private List<Endpoint> endpoints;

        [DataMember(IsRequired = false)]
        public List<Endpoint> Endpoints
        {
            get { return endpoints; }
            set { endpoints = value; }
        }

        private bool receiveNotifications = true;
        
        [DataMember(IsRequired = false)]
        public bool ReceiveNotifications
        {
            get { return receiveNotifications; }
            set { receiveNotifications = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class RuntimeServerGroup : BaseEntityGroup<RuntimeServerListElement>
    {
        [DataMember(IsRequired = false)]
        public List<RuntimeServerListElement> RuntimeServers
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    #endregion RuntimeServer

    #region Endpoint

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class EndpointList : BaseEntityList<EndpointListElement>
    {
        [DataMember(IsRequired = true)]
        public List<EndpointListElement> Endpoints
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class EndpointListElement : BaseEntityListElement 
    {
        private Int32 port;

        [DataMember(IsRequired = true)]
        public Int32 Port
        {
            get { return port; }
            set { port = value; }
        }

        string uri;

        [DataMember(IsRequired = true)]
        public string URI
        {
            get { return uri; }
            set { uri = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class Endpoint : BaseEntity 
    {
        private string address;

        [DataMember(IsRequired = false)]
        public string Address
        {
            get { return address; }
            set { address = value; }
        }

        private string path;

        [DataMember(IsRequired = true)]
        public string Path
        {
            get { return path; }
            set 
            { 
                path = value;
                name = value;
            }
        }

        private Int32 port;

        [DataMember(IsRequired = true)]
        public Int32 Port
        {
            get { return port; }
            set { port = value; }
        }

        private MSEBinding binding;

        [DataMember(IsRequired = true)]
        public MSEBinding Binding
        {
            get { return binding; }
            set { binding = value; }
        }
        private Policy policy;

        [DataMember(IsRequired = false)]
        public Policy Policy
        {
            get { return policy; }
            set { policy = value; }
        }

        private XmlElement wsdl;

        [DataMember(IsRequired = false)]
        public XmlElement WSDL
        {
            get { return wsdl; }
            set { wsdl = value; }
        }

        XmlElement configuration;

        [DataMember(IsRequired = false)]
        public XmlElement Configuration
        {
            get { return configuration; }
            set { configuration = value; }
        }

        string namespaceURI;

        [DataMember(IsRequired = true)]
        public string NamespaceURI
        {
            get { return namespaceURI; }
            set { namespaceURI = value; }
        }

        string serviceName;

        [DataMember(IsRequired = false)]
        public string ServiceName
        {
            get { return serviceName; }
            set { serviceName = value; }
        }

        

        private bool testCallsAccepted;

        [DataMember(IsRequired = false)]
        public bool TestCallsAccepted
        {
            get { return testCallsAccepted; }
            set { testCallsAccepted = value; }
        }

        private bool autoOperationPubUpdate;

        [DataMember(IsRequired = false)]
        public bool AutoOperationPubUpdate
        {
            get { return autoOperationPubUpdate; }
            set { autoOperationPubUpdate = value; }
        }

        private bool autoOperationActivationUpdate;

        [DataMember(IsRequired = false)]
        public bool AutoOperationActivationUpdate
        {
            get { return autoOperationActivationUpdate; }
            set { autoOperationActivationUpdate = value; }
        }

        private OperationVersionList assocOpVersionsList;

        [DataMember(IsRequired = false)]
        public OperationVersionList AssocOpVersionsList
        {
            get { return assocOpVersionsList; }
            set { assocOpVersionsList = value; }
        }

        private OperationVersionList pubOpVersionsList;

        [DataMember(IsRequired = false)]
        public OperationVersionList PubOpVersionsList
        {
            get { return pubOpVersionsList; }
            set { pubOpVersionsList = value; }
        }

        private List<EndpointAssociatedUddi> uddiAssociations;

        [DataMember(IsRequired = false)]
        public List<EndpointAssociatedUddi> UddiAssociations
        {
            get { return uddiAssociations; }
            set { uddiAssociations = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class EndpointAssociatedUddi
    {
        Guid uddiAssociationID;
        [DataMember(IsRequired = true)]
        public Guid UddiAssociationID
        {
            get { return uddiAssociationID; }
            set { uddiAssociationID = value; }
        }

        Guid runtimeServerID;
        [DataMember(IsRequired = true)]
        public Guid RuntimeServerID
        {
            get { return runtimeServerID; }
            set { runtimeServerID = value; }
        }

        Guid endpointID;
        [DataMember(IsRequired = true)]
        public Guid EndpointID
        {
            get { return endpointID; }
            set { endpointID = value; }
        }

        string serviceKey;
        [DataMember(IsRequired = true)]
        public string ServiceKey
        {
            get { return serviceKey; }
            set { serviceKey = value; }
        }

        string tModelKey;
        [DataMember(IsRequired = true)]
        public string TModelKey
        {
            get { return tModelKey; }
            set { tModelKey = value; }
        }

        string bindingKey;
        [DataMember(IsRequired = true)]
        public string BindingKey
        {
            get { return bindingKey; }
            set { bindingKey = value; }
        }

        string wsdlUrl;
        [DataMember(IsRequired = true)]
        public string WsdlUrl
        {
            get { return wsdlUrl; }
            set { wsdlUrl = value; }
        }

        string bindingUrl;
        [DataMember(IsRequired = true)]
        public string BindingUrl
        {
            get { return bindingUrl; }
            set { bindingUrl = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class EndpointGroup : BaseEntityGroup<EndpointListElement>
    {
        [DataMember(IsRequired = false)]
        public List<EndpointListElement> Endpoints
        {
            get { return _items; }
            set { _items = value; }
        }
    }    

    #endregion Endpoint

    #region Operation

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class OperationList : BaseEntityList<OperationListElement>
    {
        [DataMember(IsRequired = false)]
        public List<OperationListElement> Operations
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class OperationListElement : BaseEntityListElement 
    {
    }


    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class Operation : BaseEntity 
    {
        private List<OperationVersion> versions;

        [DataMember(IsRequired = false)]
        public List<OperationVersion> Versions
        {
            get { return versions; }
            set { versions = value; }
        }
        private Policy policy;

        [DataMember(IsRequired = false)]
        public Policy Policy
        {
            get { return policy; }
            set { policy = value; }
        }

        private EndpointList endpointList;

        [DataMember(IsRequired = false)]
        public EndpointList EndpointList
        {
            get { return endpointList; }
            set { endpointList = value; }
        }

    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class OperationGroup : BaseEntityGroup<OperationListElement>
    {
        [DataMember(IsRequired = false)]
        public List<OperationListElement> Operations
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    #endregion Operation

    #region OperationVersion

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class OperationVersionList : BaseEntityList<OperationVersionListElement>
    {
        [DataMember(IsRequired = false)]
        public List<OperationVersionListElement> OperationVersions
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class OperationVersionListElement :  BaseEntityListElement
    {
        String operationName;

        [DataMember(IsRequired = true)]
        public String OperationName
        {
            get { return operationName; }
            set { operationName = value; }
        }

        VersionNumber version;

        [DataMember(IsRequired = true)]
        public VersionNumber Version
        {
            get { return version; }
            set { version = value; }
        }
    }


    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class OperationVersion : BaseEntity 
    {
        Guid operationID;

        [DataMember(IsRequired = false)]
        public Guid OperationID
        {
            get { return operationID; }
            set { operationID = value; }
        }

        String operationName;

        [DataMember(IsRequired = false)]
        public String OperationName
        {
            get { return operationName; }
            set { operationName = value; }
        }

        VersionNumber version;

        [DataMember(IsRequired = true)]
        public VersionNumber Version
        {
            get { return version; }
            set { version = value; }
        }

        private List<MessagePart> requestMsg;

        [DataMember(IsRequired = false)]
        public List<MessagePart> RequestMsg
        {
            get { return requestMsg; }
            set { requestMsg = value; }
        }

        private List<MessagePart> responseMsg;

        [DataMember(IsRequired = false)]
        public List<MessagePart> ResponseMsg
        {
            get { return responseMsg; }
            set { responseMsg = value; }
        }

        private List<SoapFault> soapFaults;

        [DataMember(IsRequired = false)]
        public List<SoapFault> SoapFaults
        {
            get { return soapFaults; }
            set { soapFaults = value; }
        }

        private List<MessageHeader> requestHeaders;

        [DataMember(IsRequired = false)]
        public List<MessageHeader> RequestHeaders
        {
            get { return requestHeaders; }
            set { requestHeaders = value; }
        }

        private List<MessageHeader> responseHeaders;

        [DataMember(IsRequired = false)]
        public List<MessageHeader> ResponseHeaders
        {
            get { return responseHeaders; }
            set { responseHeaders = value; }
        }

        private XmlElement autoResponse;

        [DataMember(IsRequired = false)]
        public XmlElement AutoResponse
        {
            get { return autoResponse; }
            set { autoResponse = value; }
        }
        private bool isActive;

        [DataMember(IsRequired = true)]
        public bool IsActive
        {
            get { return isActive; }
            set { isActive = value; }
        }
        private bool isPublic;

        [DataMember(IsRequired = true)]
        public bool IsPublic
        {
            get { return isPublic; }
            set { isPublic = value; }
        }
        private bool isTestable;

        [DataMember(IsRequired = true)]
        public bool IsTestable
        {
            get { return isTestable; }
            set { isTestable = value; }
        }       

        private XmlElement requestTransformXSLT;

        [DataMember(IsRequired = false)]
        public XmlElement RequestTransformXSLT
        {
            get { return requestTransformXSLT; }
            set { requestTransformXSLT = value; }
        }
        private XmlElement responseTransformXSLT;

        [DataMember(IsRequired = false)]
        public XmlElement ResponseTransformXSLT
        {
            get { return responseTransformXSLT; }
            set { responseTransformXSLT = value; }
        }

        private Resource resource;

        [DataMember(IsRequired = false)]
        public Resource Resource
        {
            get { return resource; }
            set { resource = value; }
        }

        private Policy policy;

        [DataMember(IsRequired = false)]
        public Policy Policy
        {
            get { return policy; }
            set { policy = value; }
        }
    }

    #endregion OperationVersion

    #region MSEBinding and BindingElement

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class MSEBindingElementList : BaseEntityList<MSEBindingElementListElement>
    {
        [DataMember(IsRequired = false)]
        public List<MSEBindingElementListElement> MSEBindingElements
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class MSEBindingElementListElement : BaseEntityListElement 
    {
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class MSEBindingList : BaseEntityList<MSEBindingListElement>
    {
        [DataMember(IsRequired = false)]
        public List<MSEBindingListElement> MSEBindings
        {
            get { return _items; }
            set { _items = value; }
        }
    }


    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class MSEBindingListElement : BaseEntityListElement
    {
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class MSEBinding : BaseEntity 
    {
        XmlElement bindingConfig;

        [DataMember(IsRequired = true)]
        public XmlElement BindingConfig
        {
            get { return this.bindingConfig; }
            set { this.bindingConfig = value; }
        }

        List<MSEBindingElement> bindingElements;

        [DataMember(IsRequired = false)]
        public List<MSEBindingElement> BindingElements
        {
            get { return bindingElements; }
            set { bindingElements = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class MSEBindingElement : BaseEntity 
    {
        XmlElement bindingElementConfig;

        [DataMember(IsRequired = true)]
        public XmlElement BindingElementConfig
        {
            get { return this.bindingElementConfig; }
            set { this.bindingElementConfig = value; }
        }

        int elementOrder;

        [DataMember(IsRequired = true)]
        public int ElementOrder
        {
            get { return elementOrder; }
            set { elementOrder = value; }
        }

        BindingElementType elementType;

        [DataMember(IsRequired = true)]
        public BindingElementType ElementType
        {
            get { return elementType; }
            set { elementType = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class MSEBindingGroup : BaseEntityGroup<MSEBindingListElement>
    {
        [DataMember(IsRequired = false)]
        public List<MSEBindingListElement> MSEBindings
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    #endregion MSEBinding and MSEBindingElement

    #region Channel

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class ChannelList : BaseEntityList<ChannelListElement>
    {
        [DataMember(IsRequired = false)]
        public List<ChannelListElement> Channels
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class ChannelListElement : BaseEntityListElement
    {
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class Channel : BaseEntity 
    {
        private XmlElement monikerSchema;

        [DataMember(IsRequired = true)]
        public XmlElement MonikerSchema
        {
            get { return monikerSchema; }
            set { monikerSchema = value; }
        }
        private MSEBinding binding;

        [DataMember(IsRequired = true)]
        public MSEBinding Binding
        {
            get { return binding; }
            set { binding = value; }
        }
        private string monikerEditorAssemblyName;

        [DataMember(IsRequired = false)]
        public string MonikerEditorAssemblyName
        {
            get { return monikerEditorAssemblyName; }
            set { monikerEditorAssemblyName = value; }
        }
        private string monikerEditorTypeName;

        [DataMember(IsRequired = false)]
        public string MonikerEditorTypeName
        {
            get { return monikerEditorTypeName; }
            set { monikerEditorTypeName = value; }
        }

        private Policy[] policies;

        [DataMember(IsRequired = false)]
        public Policy[] Policies
        {
            get { return policies; }
            set { policies = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class ChannelGroup : BaseEntityGroup<ChannelListElement>
    {
        [DataMember(IsRequired = false)]
        public List<ChannelListElement> Channels
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    #endregion Channel


    #region Policy

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class PolicyList : BaseEntityList<PolicyListElement>
    {
        [DataMember(IsRequired = false)]
        public List<PolicyListElement> Policies
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class PolicyListElement : BaseEntityListElement
    {
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class Policy : BaseEntity 
    {
        private XmlElement wsPolicy;

        [DataMember(IsRequired = true)]
        public XmlElement WSPolicy
        {
            get { return wsPolicy; }
            set { wsPolicy = value; }
        }

        private EntityClass entityClass;

        [DataMember(IsRequired = false)]
        public EntityClass EntityClass
        {
            get { return entityClass; }
            set { entityClass = value; }
        }

        List<PolicyAssertion> policyAssertions;

        [DataMember(IsRequired = false)]
        public List<PolicyAssertion> PolicyAssertions
        {
            get { return policyAssertions; }
            set { policyAssertions = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class PolicyGroup : BaseEntityGroup<PolicyListElement>
    {
        [DataMember(IsRequired = false)]
        public List<PolicyListElement> Policies
        {
            get { return _items; }
            set { _items = value; }
        }
    }   

    #endregion Policy

    #region AssertionType

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class AssertionTypeList : BaseEntityList<AssertionTypeListElement>
    {
        [DataMember(IsRequired = false)]
        public List<AssertionTypeListElement> AssertionTypes
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class AssertionTypeListElement : BaseEntityListElement 
    {
    }
    
    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class AssertionType : BaseEntity 
    {
        private SchemaObject schemaObject;

        [DataMember(IsRequired = true)]
        public SchemaObject SchemaObject
        {
            get { return schemaObject; }
            set { schemaObject = value; }
        }
        private string assertionImplementationType;

        [DataMember(IsRequired = false)]
        public string AssertionImplementationType
        {
            get { return assertionImplementationType; }
            set { assertionImplementationType = value; }
        }

        private EntityClass[] assertionTypeSubjects;
        
        [DataMember(IsRequired = false)]
        public EntityClass[] AssertionTypeSubjects
        {
            get { return assertionTypeSubjects; }
            set { assertionTypeSubjects = value; }
        }
    }
    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class AssertionTypeGroup : BaseEntityGroup<AssertionTypeListElement>
    {
        [DataMember(IsRequired = false)]
        public List<AssertionTypeListElement> AssertionTypes
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    #endregion AssertionType

    #region PolicyAssertion

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class PolicyAssertionList : BaseEntityList<PolicyAssertionListElement>
    {
        [DataMember(IsRequired = false)]
        public List<PolicyAssertionListElement> PolicyAssertions
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class PolicyAssertionListElement : BaseEntityListElement 
    {
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class PolicyAssertion : BaseEntity 
    {
        private AssertionType assertionType;

        [DataMember(IsRequired = true)]
        public AssertionType AssertionType
        {
            get { return assertionType; }
            set { assertionType = value; }
        }

        private XmlElement assertion;

        [DataMember(IsRequired = true)]
        public XmlElement Assertion
        {
            get { return assertion; }
            set { assertion = value; }
        }

        int assertionOrder;

        [DataMember(IsRequired = true)]
        public int AssertionOrder
        {
            get { return assertionOrder; }
            set { assertionOrder = value; }
        }
    }
    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class PolicyAssertionGroup : BaseEntityGroup<PolicyAssertionListElement>
    {
        [DataMember(IsRequired = false)]
        public List<PolicyAssertionListElement> PolicyAssertions
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    #endregion PolicyAssertion

    #region Resource

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class ResourceList : BaseEntityList<ResourceListElement>
    {
        [DataMember(IsRequired = false)]
        public List<ResourceListElement> Resources
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class ResourceListElement : BaseEntityListElement
    {
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class Resource : BaseEntity 
    {
        private Guid instanceID;

        [DataMember(IsRequired = false)]
        public Guid InstanceID
        {
            get { return instanceID; }
            set { instanceID = value; }
        }

        private string idl;

        [DataMember(IsRequired = false)]
        public string IDL
        {
            get { return idl; }
            set { idl = value; }
        }

        private string idlType;

        [DataMember(IsRequired = false)]
        public string IDLType
        {
            get { return idlType; }
            set { idlType = value; }
        }

        private MSEBinding binding;

        [DataMember(IsRequired = false)]
        public MSEBinding Binding
        {
            get { return binding; }
            set { binding = value; }
        }

        private XmlElement moniker;

        [DataMember(IsRequired = false)]
        public XmlElement Moniker
        {
            get { return moniker; }
            set { moniker = value; }
        }

        private SchemaObject requestSchemaObject;

        [DataMember(IsRequired = false)]
        public SchemaObject RequestSchemaObject
        {
            get { return requestSchemaObject; }
            set { requestSchemaObject = value; }
        }

        private SchemaObject responseSchemaObject;

        [DataMember(IsRequired = false)]
        public SchemaObject ResponseSchemaObject
        {
            get { return responseSchemaObject; }
            set { responseSchemaObject = value; }
        }

        private string uri;

        [DataMember(IsRequired = true)]
        public string URI
        {
            get { return uri; }
            set { uri = value; }
        }

        private Policy policy;

        [DataMember(IsRequired = false)]
        public Policy Policy
        {
            get { return policy; }
            set { policy = value; }
        }

        private bool shareableProxy;

        [DataMember(IsRequired = false)]
        public bool ShareableProxy
        {
            get { return shareableProxy; }
            set { shareableProxy = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class ResourceGroup : BaseEntityGroup<ResourceListElement>
    {
        [DataMember(IsRequired = false)]
        public List<ResourceListElement> Resources
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    #endregion Resource

    #region SystemInstance

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class SystemInstanceList : BaseEntityList<SystemInstanceListElement>
    {
        [DataMember(IsRequired = false)]
        public List<SystemInstanceListElement> SystemInstances
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class SystemInstanceListElement : BaseEntityListElement
    {
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class SystemInstance : BaseEntity 
    {
        private Guid systemID;

        [DataMember(IsRequired = false)]
        public Guid SystemID
        {
            get { return systemID; }
            set { systemID = value; }
        }

        private string ownerName;

        [DataMember(IsRequired = false)]
        public string OwnerName
        {
            get { return ownerName; }
            set { ownerName = value; }
        }

        private string ownerContact;

        [DataMember(IsRequired = false)]
        public string OwnerContact
        {
            get { return ownerContact; }
            set { ownerContact = value; }
        }

        private string uri;

        [DataMember(IsRequired = false)]
        public string URI
        {
            get { return uri; }
            set { uri = value; }
        }

        private Int32 port;

        [DataMember(IsRequired = true)]
        public Int32 Port
        {
            get { return port; }
            set { port = value; }
        }

        private Policy policy;

        [DataMember(IsRequired = false)]
        public Policy Policy
        {
            get { return policy; }
            set { policy = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class SystemInstanceGroup : BaseEntityGroup<SystemInstanceListElement>
    {
        [DataMember(IsRequired = false)]
        public List<SystemInstanceListElement> SystemInstances
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    #endregion SystemInstance

    #region System

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class SystemList : BaseEntityList<SystemListElement>
    {
        [DataMember(IsRequired = false)]
        public List<SystemListElement> Systems
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class SystemListElement : BaseEntityListElement 
    {
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class System : BaseEntity 
    {
        private string ownerName;

        [DataMember(IsRequired = false)]
        public string OwnerName
        {
            get { return ownerName; }
            set { ownerName = value; }
        }

        private string ownerContact;

        [DataMember(IsRequired = false)]
        public string OwnerContact
        {
            get { return ownerContact; }
            set { ownerContact = value; }
        }

        private string location;

        [DataMember(IsRequired = false)]
        public string Location
        {
            get { return location; }
            set { location = value; }
        }

        private string uri;

        [DataMember(IsRequired = false)]
        public string URI
        {
            get { return uri; }
            set { uri = value; }
        }

        private Policy policy;

        [DataMember(IsRequired = false)]
        public Policy Policy
        {
            get { return policy; }
            set { policy = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class SystemGroup : BaseEntityGroup<SystemListElement>
    {
        [DataMember(IsRequired = false)]
        public List<SystemListElement> Systems
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    #endregion System

    #region Schema and SchemaObject
    
    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class SchemaList : BaseEntityList<SchemaListElement>
    {
        [DataMember(IsRequired = false)]
        public List<SchemaListElement> Schemas
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class SchemaListElement : BaseEntityListElement
    {
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class SchemaObject : BaseEntity 
    {
        private string namespaceUri;

        private XmlElement xml;

        private SchemaObjectType type;

        private SchemaObjectList dependencies;

        private SchemaObjectRevision revision;


        [DataMember(IsRequired = true)]
        public XmlElement Xml
        {
            get { return xml; }
            set { xml = value; }
        }

        [DataMember(IsRequired = true)]
        public SchemaObjectType Type
        {
            get { return type; }
            set { type = value; }
        }

        [DataMember(IsRequired = false)]
        public SchemaObjectList Dependencies
        {
            get { return dependencies; }
            set { dependencies = value; }
        }

        [DataMember(IsRequired = false)]
        public string NamespaceUri
        {
            get { return namespaceUri; }
            set { namespaceUri = value; }
        }

        [DataMember(IsRequired = false)]
        public SchemaObjectRevision Revision
        {
            get { return revision; }
            set { revision = value; }
        }

        Guid dataEntityID;

        [DataMember(IsRequired = false)]
        public Guid DataEntityID
        {
            get { return dataEntityID; }
            set { dataEntityID = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class SchemaObjectRevision
    {
        private bool isLatest;

        [DataMember(IsRequired = false)]
        public bool IsLatest
        {
            get { return isLatest; }
            set { isLatest = value; }
        }

        private DateTime dateRevised;

        [DataMember(IsRequired = false)]
        public DateTime DateRevised
        {
            get { return dateRevised; }
            set { dateRevised = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class SchemaObjectListElement : BaseEntityListElement
    {
        private SchemaObjectType type;

        private string namespaceUri;

        [DataMember(IsRequired = true)]
        public SchemaObjectType Type
        {
            get { return type; }
            set { type = value; }
        }

        [DataMember(IsRequired = true)]
        public string NamespaceUri
        {
            get { return namespaceUri; }
            set { namespaceUri = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class SchemaObjectList : BaseEntityList<SchemaObjectListElement>
    {
        [DataMember(IsRequired = false)]
        public List<SchemaObjectListElement> SchemaObjects
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class Schema : BaseEntity 
    {

        private string namespaceURI;

        private XmlElement xsd;

        private List<SchemaImport> importedSchemas;

        private List<SchemaObject> objects;

        [DataMember(IsRequired = false)]
        public List<SchemaObject> Objects
        {
            get { return objects; }
            set { objects = value; }
        }

        [DataMember(IsRequired = false)]
        public List<SchemaImport> ImportedSchemas
        {
            get { return importedSchemas; }
            set { importedSchemas = value; }
        }

        [DataMember(IsRequired = true)]
        public string NamespaceURI
        {
            get
            {
                return this.namespaceURI;
            }
            set
            {
                this.namespaceURI = value;
                this.name = value;
            }
        }

        [DataMember(IsRequired = true)]
        public XmlElement XSD
        {
            get
            {
                return this.xsd;
            }
            set
            {
                this.xsd = value;
            }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class SchemaImport
    {

        private Guid id;

        private string namespaceURI;

        [DataMember(IsRequired = false)]
        public Guid ID
        {
            get
            {
                return this.id;
            }
            set
            {
                this.id = value;
            }
        }

        [DataMember(IsRequired = true)]
        public string NamespaceURI
        {
            get
            {
                return this.namespaceURI;
            }
            set
            {
                this.namespaceURI = value;
            }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class SchemaGroup : BaseEntityGroup<SchemaListElement>
    {
        [DataMember(IsRequired = false)]
        public List<SchemaListElement> Schemas
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    #endregion Schema and SchemaObject

    #region DataEntity

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class DataEntity : BaseEntity 
    {
        List<SchemaObject> schemaObjects;

        [DataMember(IsRequired = false)]
        public List<SchemaObject> SchemaObjects
        {
            get { return schemaObjects; }
            set { schemaObjects = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class DataEntityListElement : BaseEntityListElement 
    {
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class DataEntityList :  BaseEntityList<DataEntityListElement>
    {
        [DataMember(IsRequired = false)]
        public List<DataEntityListElement> DataEntities
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class DataEntityGroup : BaseEntityGroup<DataEntityListElement>
    {
        [DataMember(IsRequired = false)]
        public List<DataEntityListElement> DataEntities
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    #endregion DataEntity

    #region Property, MessagePart, SoapFault, MessageHeader, VersionNumber

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class PropertyList : BaseEntityList<PropertyListElement>
    {
        [DataMember(IsRequired = false)]
        public List<PropertyListElement> Properties
        {
            get { return _items; }
            set { _items = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class PropertyListElement : BaseEntityListElement 
    {
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class Property : BaseEntity
    {
        XmlElement value;

        [DataMember(IsRequired = true)]
        public XmlElement Value
        {
            get { return this.value; }
            set { this.value = value; }
        }
        string description;
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class MessagePart
    {
        private SchemaObject schemaObject;

        [DataMember(IsRequired = true)]
        public SchemaObject SchemaObject
        {
            get { return schemaObject; }
            set { schemaObject = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class SoapFault :  BaseEntity 
    {
        private SchemaObject schemaObject;

        [DataMember(IsRequired = true)]
        public SchemaObject SchemaObject
        {
            get { return schemaObject; }
            set { schemaObject = value; }
        }

        private string action;

        [DataMember(IsRequired = false)]
        public string Action
        {
            get { return action; }
            set { action = value; }
        }

        private CLRNet.Security.ProtectionLevel protectionLevel;

        [DataMember(IsRequired = false)]
        public CLRNet.Security.ProtectionLevel ProtectionLevel
        {
            get { return protectionLevel; }
            set { protectionLevel = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class MessageHeader : BaseEntity 
    {
        private SchemaObject schemaObject;

        [DataMember(IsRequired = true)]
        public SchemaObject SchemaObject
        {
            get { return schemaObject; }
            set { schemaObject = value; }
        }

        private bool isRequired;

        [DataMember(IsRequired = false)]
        public bool IsRequired
        {
            get { return isRequired; }
            set { isRequired = value; }
        }

        private CLRNet.Security.ProtectionLevel protectionLevel;

        [DataMember(IsRequired = false)]
        public CLRNet.Security.ProtectionLevel ProtectionLevel
        {
            get { return protectionLevel; }
            set { protectionLevel = value; }
        }
    }

    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class VersionNumber
    {
        private string major;

        [DataMember(IsRequired = true)]
        public string Major
        {
            get { return major; }
            set { major = value; }
        }
        private string minor;

        [DataMember(IsRequired = true)]
        public string Minor
        {
            get { return minor; }
            set { minor = value; }
        }
        private string build;

        [DataMember(IsRequired = true)]
        public string Build
        {
            get { return build; }
            set { build = value; }
        }
        private string qfe;

        [DataMember(IsRequired = true)]
        public string Qfe
        {
            get { return qfe; }
            set { qfe = value; }
        }
    }

    #endregion Property, MessagePart, SoapFault, MessageHeader, VersionNumber


    [DebuggerStepThrough]
    [DataContract(Namespace = SC.Namespace)]
    public class OperationGroupList
    {
        List<EntityGroupListElement> operationGroups;

        [DataMember(IsRequired = false)]
        public List<EntityGroupListElement> OperationGroups
        {
            get { return operationGroups; }
            set { operationGroups = value; }
        }
    }
}
